<?php
/**
 * Joomla! 1.5 component NS Pro
 *
 * @version $Id: view.html.php 2009-04-28 01:47:12 svn $
 * @author Christopher Mavros
 * @package Joomla
 * @subpackage NS Pro
 * @license GNU/GPL
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the NS Pro component
 */
class NsproViewNspro extends JView {

  function display($tpl = null) {
    //global $mainframe;
    $mainframe = JFactory::getApplication();

    $model = $this->getModel();

    $subs = $model->getSubs();
    $subsCount = $model->getSubsCount();

    $jversion = new JVersion();
    $j15 = ($jversion->RELEASE == '1.5');
    $this->assignRef('j15', $j15);
    
    jimport('joomla.application.component.helper');
    $params = JComponentHelper::getParams( 'com_nspro' );
    if ($j15 == true) {
      $component = JComponentHelper::getComponent( 'com_nspro' );
      $params = new JParameter( $component->params );
    }


    $confirmUnsub = $params->get( 'send_unsub_confirm', '1' );

    $notifyUnsub = $params->get( 'send_unsub', '1' );

    $myEmailLabel = $params->get('unsub_email_label', 'Email:');
    $buttonText = $params->get('unsub_button_text', 'Unsubscribe from Newsletter');
    $emailWidth = $params->get('unsub_email_width', '20');
    $buttonWidth = $params->get('unsub_button_width', '100');
    $unsub_pre_text = $params->get('unsub_pre_text', '');

    $recipient = $params->get('unsub_mail_recipient', 'email@email.com');
    $subject = $params->get('unsub_subject', 'Unsubscription from your site..');
    $fromName = $params->get('unsub_from_name', 'Newsletter Subscriber');
    $fromEmail = $params->get('unsub_from_email', 'newsletter_subscriber@yoursite.com');

    if ($fromName == 'Newsletter Subscriber') {
      $fromName = $mainframe->getCfg('fromname');
    }
    if ($fromEmail == 'newsletter_subscriber@yoursite.com') {
      $fromEmail = $mainframe->getCfg('mailfrom');
    }

    $sendingWithSetEmail = $params->get('unsub_sending_from_set', true);

    $fromNameConfirm = $params->get('from_name_confirm', 'Newsletter Subscriber');
    $fromEmailConfirm = $params->get('from_email_confirm', 'newsletter_subscriber@yoursite.com');

    if ($fromNameConfirm == 'Newsletter Subscriber') {
      $fromNameConfirm = $mainframe->getCfg('fromname');
    }
    if ($fromEmailConfirm == 'newsletter_subscriber@yoursite.com') {
      $fromEmailConfirm = $mainframe->getCfg('mailfrom');
    }

    $subjectConfirm = $params->get('subject_confirm', 'Subscription Confirmation');

    $fromNameConfirmun = $params->get('unsub_from_name_confirm', 'Newsletter Subscriber');
    $fromEmailConfirmun = $params->get('unsub_from_email_confirm', 'newsletter_subscriber@yoursite.com');

    if ($fromNameConfirmun == 'Newsletter Subscriber') {
      $fromNameConfirmun = $mainframe->getCfg('fromname');
    }
    if ($fromEmailConfirmun == 'newsletter_subscriber@yoursite.com') {
      $fromEmailConfirmun = $mainframe->getCfg('mailfrom');
    }

    $subjectConfirmun = $params->get('unsub_subject_confirm', 'Unsubscription Confirmation');
    
    $redirectToPage = $params->get('confirm_redirect', false);
    $redirectPage = $params->get('confirm_redir_page', false);
    $redirectMethod = $params->get('confirm_redir_method', 0);
    

    $uredirectToPage = $params->get('unsub_confirm_redirect', false);
    $uredirectPage = $params->get('unsub_confirm_redir_page', false);
    
    $unsub_completed_color = $params->get('unsub_completed_color', '#000');
    $unsub_error_color = $params->get('unsub_error_color', '#f00');
    
    $show_id = $params->get('show_id', true);
		$show_subject = $params->get('show_subject', true);
    $show_datetime = $params->get('show_datetime', false);
    
    $newsletter_order = $params->get('newsletter_order', '0');
    

    $this->assignRef('subs', $subs);
    $this->assignRef('subsCount', $subsCount);

    $this->assignRef('params', $params);

    $this->assignRef('confirmUnsub', $confirmUnsub);
    $this->assignRef('notifyUnsub', $notifyUnsub);

    $this->assignRef('myEmailLabel', $myEmailLabel);
    $this->assignRef('recipient', $recipient);
    $this->assignRef('buttonText', $buttonText);
    $this->assignRef('subject', $subject);
    $this->assignRef('fromName', $fromName);
    $this->assignRef('fromEmail', $fromEmail);
    $this->assignRef('fromNameConfirm', $fromNameConfirm);
    $this->assignRef('fromEmailConfirm', $fromEmailConfirm);
    $this->assignRef('subjectConfirm', $subjectConfirm);
    $this->assignRef('fromNameConfirmun', $fromNameConfirmun);
    $this->assignRef('fromEmailConfirmun', $fromEmailConfirmun);
    $this->assignRef('subjectConfirmun', $subjectConfirmun);
    $this->assignRef('sendingWithSetEmail', $sendingWithSetEmail);
    $this->assignRef('emailWidth', $emailWidth);
    $this->assignRef('buttonWidth', $buttonWidth);
    $this->assignRef('unsub_pre_text', $unsub_pre_text);
    
    $this->assignRef('redirectToPage', $redirectToPage);
    $this->assignRef('redirectPage', $redirectPage);
    $this->assignRef('redirectMethod', $redirectMethod);
    
    $this->assignRef('uredirectToPage', $uredirectToPage);
    $this->assignRef('uredirectPage', $uredirectPage);
    
    $this->assignRef('unsub_completed_color', $unsub_completed_color);
    $this->assignRef('unsub_error_color', $unsub_error_color);
    
    $this->assignRef('show_id', $show_id);
    $this->assignRef('show_subject', $show_subject);
    $this->assignRef('show_datetime', $show_datetime);
    
    $this->assignRef('newsletter_order', $newsletter_order);

    parent::display($tpl);
  }
}
?>